home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Telnet 2.6.1d1 4⁄26⁄94 Folder / source / main / maclook.c < prev    next >
Text File  |  1994-04-14  |  9KB  |  332 lines

  1. /*
  2. *    maclook.c
  3. *    User interface code for NCSA Telnet for the Macintosh
  4. *     by Gaige B. Paulsen
  5. *****************************************************************
  6. *    NCSA Telnet for the Macintosh                                *
  7. *                                                                *
  8. *    National Center for Supercomputing Applications                *
  9. *    Software Development Group                                    *
  10. *    152 Computing Applications Building                            *
  11. *    605 E. Springfield Ave.                                        *
  12. *    Champaign, IL  61820                                        *
  13. *                                                                *
  14. *    Copyright (c) 1986-1992,                                    *
  15. *    Board of Trustees of the University of Illinois                *
  16. *****************************************************************
  17. *
  18. *   User interface for basic telnet with background file transfer
  19. *   capabilities via FTP calls from host.
  20. *
  21. *    This, the Macintosh version also gives each session its own window,
  22. *    provides advanced keyboard translation, Tek emulation, printing/copying
  23. *    of text and graphics and the pasting of text into the active session.
  24. *
  25. *        Requires:
  26. *    menu.c    - Aux. file for handling menu calls
  27. *    event.c    - Aux. file for handling events
  28. *    switch.c- Aux. file for handling swithcher  (the J word is in Event and here )
  29. *
  30. *
  31. *    Revisions:
  32. *    7/92 Telnet 2.6: added support for the 2 global structs, and put all the 
  33. *                    cursors into one array.  Cleaned up defines            Scott Bulmahn
  34. */
  35.  
  36. #ifdef MPW
  37. #pragma segment 4
  38. #endif
  39.  
  40. #include "TelnetHeader.h"
  41.  
  42. #define PREFMASTER                    /* So pref structure gets defined Scott! */
  43.  
  44. #include <stdio.h>
  45. #include <string.h>
  46. #include <stdlib.h>
  47.  
  48. #include <CType.h>
  49. #include <Fonts.h>
  50. #include <Types.h>
  51. #include <Windows.h>
  52. #include <OSEvents.h>
  53.  
  54. #include "netevent.proto.h"
  55. #include "wind.h"
  56. #include "event.proto.h"
  57. #include "macutil.proto.h"
  58. #include "popup.h"
  59. #include "popup.proto.h"
  60.  
  61. #include "rsmac.proto.h"
  62. #include "vsdata.h"
  63. #include "vskeys.h"
  64. #include "vsinterf.proto.h"
  65. #include "vgtek.proto.h"
  66. #include "tekrgmac.proto.h"
  67. #include "vr.h"
  68. #include "vrrgmac.proto.h" 
  69. #include "network.proto.h"
  70. #include "mydnr.proto.h"
  71. #include "menuseg.proto.h"
  72. #include "prefs.proto.h"
  73. #include "maclook.proto.h"
  74. #include "DlogUtils.proto.h"
  75. #include "telneterrors.h"
  76.  
  77. extern    Cursor *theCursors[];
  78. extern    WindRec
  79.     *screens;        /* Window Records (VS) for :    Current Sessions */
  80.  
  81. extern    short    scrn;
  82. extern    char    *tempspot;                /* temporary storage ~255 bytes malloc-ed */
  83.  
  84. void MiscUnload(void) {}
  85.  
  86. short detachGraphics( short dnum)
  87. {
  88.     short i=0;
  89.  
  90.     while((i<TelInfo->numwindows) && (dnum!=screens[i].curgraph)) i++;
  91.     if (i>=TelInfo->numwindows) return(-1);
  92.     TelInfo->oldgraph[TelInfo->graphs++]=dnum;
  93.     screens[i].curgraph=-1;
  94.     screens[i].termstate=VTEKTYPE;
  95.     screens[i].enabled=1;
  96.     RGdetach(dnum);
  97.     return(0);
  98. }
  99.  
  100. /* Find screen index by Window */
  101. short    WindowPtr2ScreenIndex(WindowPtr wn)
  102. {
  103.     short    i=0;
  104.  
  105.     while((i<TelInfo->numwindows) && (wn!= (WindowPtr)screens[i].wind)) i++;
  106.     if (i>=TelInfo->numwindows) return(-1);
  107.     return(i);
  108. }
  109.  
  110. /* Find screen index by VS Number */
  111. short findbyVS( short vs)
  112. {
  113.     short i=0;
  114.  
  115.     while((i<TelInfo->numwindows) && (vs!=screens[i].vs)) i++;
  116.     if (i>=TelInfo->numwindows) return(-1);
  117.     return(i);
  118. }
  119.  
  120. void setgraphcurs( void)                /* Called at start of gin */
  121. {
  122.     TelInfo->ginon=1;
  123.     updateCursor(1);
  124. }
  125.  
  126. void unsetgraphcurs( void)                /* Called at start of gin */
  127. {
  128.     TelInfo->ginon=0;
  129.     updateCursor(1);
  130. }
  131.  
  132. short VGalive( short dnum)
  133. {
  134.     short i;
  135.  
  136.     i=0;
  137.     while((i<TelInfo->numwindows) && (dnum!=screens[i].curgraph)) i++;
  138.     if (i<TelInfo->numwindows) {
  139.         return(1);
  140.         }
  141.     else {
  142.         i=0;
  143.         while ((i<TelInfo->graphs) && (dnum!=TelInfo->oldgraph[i])) i++;
  144.         if (i<TelInfo->graphs)
  145.             return(1);
  146.         }
  147.     return(0);
  148. }
  149.  
  150. void destroyGraphics( short dnum)
  151. {
  152.     short i;
  153.  
  154.     i=0;
  155.     while((i<TelInfo->numwindows) && (dnum!=screens[i].curgraph)) i++;
  156.     if (i<TelInfo->numwindows) {
  157.         screens[i].curgraph=-1;
  158.         screens[i].termstate=VTEKTYPE;
  159.         screens[i].enabled=1;
  160.         }
  161.     else {
  162.         i=0;
  163.         while ((i<TelInfo->graphs) && (dnum!=TelInfo->oldgraph[i])) i++;
  164.         while (i<(MaxGraph-1))
  165.             TelInfo->oldgraph[i]=TelInfo->oldgraph[++i];            /* Bump everyone down one slot */
  166.         TelInfo->graphs--;                                /* One less graph to feed */
  167.         }
  168.     VGclose( dnum);
  169. }
  170.  
  171. short FindByVG(short vg)
  172. {
  173.     short i=0;
  174.  
  175.     while((i<TelInfo->numwindows) && (vg!=screens[i].curgraph)) i++;
  176.     if (i>=TelInfo->numwindows) return(-1);
  177.     return(i);
  178. }
  179.  
  180. void TekEnable( short vg)
  181. {
  182.     short change;
  183.  
  184.     change=FindByVG( vg);
  185.     if (change>=0)
  186.         screens[change].enabled=1;
  187. }
  188.  
  189. void    TekDisable( short vg)
  190. {
  191.     short change;
  192.  
  193.     change=FindByVG( vg);
  194.     if (change>=0)
  195.         screens[change].enabled=0;
  196. }
  197.  
  198. /* showNetNumbers    - Show the current network numbers. */
  199. void showNetNumbers( void)
  200. {
  201.     char        tmpout[30];            /* IP Number */
  202.  
  203.     DialogPtr    dptr;                /* dialog box pointer */
  204.     short        scratchshort;
  205.     int            tmp[4];                /* Integer copy of IP Number */
  206.     unsigned char tmp2[4];
  207.     
  208.     netgetip(tmp2);
  209.     for(scratchshort=0; scratchshort<4; scratchshort++)
  210.             tmp[scratchshort] = (int)tmp2[scratchshort];        /* Get integer numbers */
  211.  
  212.     sprintf(&tmpout[0],"%d.%d.%d.%d",tmp[0],tmp[1],tmp[2],tmp[3]);
  213.                                         /* create Human-readable numbers */
  214.  
  215.  
  216.     c2pstr(tmpout);                                    /* BYU LSC */
  217.  
  218.     ParamText(0L, (StringPtr)tmpout,0L,0L);                /* BYU LSC - Put Parms in Dlog */
  219.     
  220.     dptr = GetNewMyDialog(MyIPDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  221.     DrawDialog(dptr);                            /* Display Dialog */
  222.  
  223.     ModalDialog(NULL, &scratchshort);            /* Wait for a click */
  224.  
  225.     DisposDialog(dptr);
  226. }
  227.  
  228. /*******************************************************************/
  229. /*  setupkeys
  230. *   Prompt the user for which keys to use for kill, stop and start.
  231. */
  232.  
  233. void setupkeys( void)
  234. {
  235.     DialogPtr dtemp;
  236.     Rect dBox;
  237.     short dItem,kItem,sItem,eItem;
  238.     Handle kbox,sbox,ebox;
  239.     
  240.     dtemp=GetNewMyDialog( SetupDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  241.  
  242.     SetCursor(theCursors[normcurs]);
  243.     
  244.     GetDItem( dtemp, killbox, &kItem, &kbox, &dBox);    
  245.     GetDItem( dtemp, stopbox, &eItem, &ebox, &dBox);    
  246.     GetDItem( dtemp, startbox, &sItem, &sbox, &dBox);    
  247.  
  248.     *tempspot = 0;
  249.     if (screens[scrn].TELstop > 0) {
  250.         sprintf(tempspot,"^%c",screens[scrn].TELstop^64);
  251.         c2pstr(tempspot);                                    /* BYU LSC */
  252.         SetIText( ebox , (StringPtr)tempspot);
  253.         SelIText( dtemp, stopbox, 0, 32767);
  254.         }
  255.     if (screens[scrn].TELgo > 0) {
  256.         sprintf(tempspot,"^%c",screens[scrn].TELgo^64);
  257.         c2pstr(tempspot);                                    /* BYU LSC */
  258.         SetIText( sbox , (StringPtr)tempspot);
  259.         SelIText( dtemp, startbox, 0, 32767);
  260.         }
  261.     if (screens[scrn].TELip > 0) {
  262.         sprintf(tempspot,"^%c",screens[scrn].TELip^64);
  263.         c2pstr(tempspot);                                    /* BYU LSC */
  264.         SetIText( kbox , (StringPtr)tempspot);
  265.         SelIText( dtemp, killbox, 0, 32767);
  266.         }
  267.     
  268.         dItem=0;                                /* initially no hits */
  269.         while((dItem>3) || (dItem==0)) {        /* While we are in the loop */
  270.             ModalDialog(DLOGwOK_CancelUPP,&dItem);
  271.  
  272. /*
  273. *  intermediate check.  If they hit a key, put its number in the box.
  274. */
  275.             GetIText( kbox, (StringPtr)tempspot);                    /* BYU LSC - Get the string */
  276.             p2cstr((StringPtr)tempspot);                            /* BYU LSC */
  277.             if (*tempspot < 32 && *tempspot > 0) {
  278.                 sprintf(tempspot,"^%c",*tempspot^64);
  279.                 c2pstr(tempspot);                        /* BYU LSC */
  280.                 SetIText( kbox , (StringPtr)tempspot);                /* BYU LSC */
  281.                 SelIText( dtemp, killbox, 0, 32767 );
  282.                 }
  283.             GetIText( ebox, (StringPtr)tempspot);                    /* BYU LSC - Get the string */
  284.             p2cstr((StringPtr)tempspot);                            /* BYU LSC */
  285.             if (*tempspot < 32 && *tempspot > 0) {
  286.                 sprintf(tempspot,"^%c",*tempspot^64);
  287.                 c2pstr(tempspot);                        /* BYU LSC */
  288.                 SetIText( ebox , (StringPtr)tempspot);                /* BYU LSC */
  289.                 SelIText( dtemp, stopbox, 0, 32767);
  290.                 }
  291.             GetIText( sbox, (StringPtr)tempspot);                    /* BYU LSC - Get the string */
  292.             p2cstr((StringPtr)tempspot);                            /* BYU LSC */
  293.             if (*tempspot < 32 && *tempspot > 0) {
  294.                 sprintf(tempspot,"^%c",*tempspot^64);
  295.                 c2pstr(tempspot);                        /* BYU LSC */
  296.                 SetIText( sbox , (StringPtr)tempspot);                /* BYU LSC */
  297.                 SelIText( dtemp, startbox, 0, 32767);
  298.                 }
  299.                 
  300.             }
  301.                 
  302.     
  303.         if (dItem==DLOGCancel) {
  304.             DisposDialog( dtemp);
  305.             return;
  306.             }
  307.             
  308.         GetIText( kbox, (StringPtr)tempspot);            /* BYU LSC - Get the string */
  309.         p2cstr((StringPtr)tempspot);                    /* BYU LSC */
  310.         if (*tempspot != '^') 
  311.             screens[scrn].TELip = -1;
  312.         else
  313.             screens[scrn].TELip = toupper(*(tempspot+1)) ^ 64;
  314.             
  315.         GetIText( ebox, (StringPtr)tempspot);            /* BYU LSC - Get the string */
  316.         p2cstr((StringPtr)tempspot);                    /* BYU LSC */
  317.         if (*tempspot != '^') 
  318.             screens[scrn].TELstop = -1;
  319.         else
  320.             screens[scrn].TELstop = toupper(*(tempspot+1)) ^ 64;
  321.  
  322.         GetIText( sbox, (StringPtr)tempspot);            /* BYU LSC - Get the string */
  323.         p2cstr((StringPtr)tempspot);                    /* BYU LSC */
  324.         if (*tempspot != '^') 
  325.             screens[scrn].TELgo = -1;
  326.         else
  327.             screens[scrn].TELgo = toupper(*(tempspot+1)) ^ 64;
  328.             
  329.     DisposDialog( dtemp);
  330.     updateCursor(1);
  331. }
  332.